package main

import (
	"fmt"
	"github.com/robfig/cron/v3"
	"time"
)

func main() {

	// 定义要获取时间表达的cron表达式
	//cron.New(cron.WithSeconds())  开启支持秒级定义
	cronExpression := "0 0 1 1 *"

	schedule, err := cron.ParseStandard(cronExpression)
	if err != nil {
		fmt.Println("解析Cron表达式错误:", err)
		return
	}
	// 获取下10次执行时间
	now := time.Now()
	for i := 1; i <= 10; i++ {
		nextTime := schedule.Next(now)
		fmt.Printf("下一次执行时间 #%d: %s\n", i, nextTime.Format("2006-01-02 15:04:05"))
		now = nextTime
	}
}
